import java.util.ArrayList;

public class Test8 {
    public static void main(String[] args) {
        //1.建立集合
        ArrayList<Phone> list = new ArrayList<>();
        //2.导入数据
        Phone p1 = new Phone("小米", 1000);
        Phone p2 = new Phone("苹果", 8000);
        Phone p3 = new Phone("锤子", 2999);
        //3.添加数据
        list.add(p1);
        list.add(p2);
        list.add(p3);
        //4.调用函数
        ArrayList<Phone> phoneInfo = getPhoneInfo(list);
        for (int i = 0; i < phoneInfo.size(); i++) {
            Phone phone = phoneInfo.get(i);
            System.out.println(phone.getBrand() + "," + phone.getPrice());
        }


    }

    public static ArrayList<Phone> getPhoneInfo(ArrayList<Phone> list) {
        //定义一个集合用于储存价格低于3000的手机对象
        ArrayList<Phone> resultList = new ArrayList<>();
        //遍历集合
        for (int i = 0; i < list.size(); i++) {
            Phone p = list.get(i);
            int price = p.getPrice();
            if (price < 3000) {
                resultList.add(p);
            }
        }
        return resultList;
    }
}
